﻿
@{
    ViewBag.Title = "我的订餐";
    Layout = "~/Areas/Mall/Views/Shared/FoodLayout.cshtml";
}
<style>
    * {
        margin: 0 auto;font-family: '微软雅黑';
    }
    .order_list{width: 95%;height: auto; overflow: hidden;margin-top: 15px; -webkit-box-shadow:0 0 5px #666666; float: left;margin-left: 2.5%; 
        -moz-box-shadow:0 0 5px #666666;  
        box-shadow:0 0 5px #666666;
        margin-bottom: 10px;
    }
    .order_info{width: 100%;font-size: 12px;height: 30px;line-height: 30px; }
    .order_g{width: 100%;height: 50px;margin-top: 10px;border-bottom: 1px #cccccc solid;}
    .order_g img{width: 20%;float: left;height: 100%;}
    .order_g div{width: 77%;float: right;font-size: 12px;}
    .orderxj{text-align: right;color: red;}
    .ordert_j{width: 100%;height: 40px;  font-size: 12px;line-height: 20px;}
    .order_fk{width: 100%;height: 40px;  font-size: 12px;}
    .title{width: 100%;height: 30px;background: #ff3333;color:#fff;text-align: center;}
    .order_fk_op{width: 70px;height: 30px;background-color: #ff3333;border-radius: 5px;float: right;font-size: 14px; text-align: center; line-height: 30px;color:white;margin-right: 10px;}
    .exitorder{width: 70px;height: 29px;border: 1px #ff3333 solid;border-radius: 5px; float: right;margin-right: 30px;font-size: 14px; text-align: center; line-height: 28px;color:#ff3333;}
    #list{width: 100%;height: auto;overflow: hidden;}
    .title_t{width: 100%;height: 30px;background: #ff3333; text-align: center;color: white;font-size: 15px;line-height: 30px;}
</style>

<div class="title_t">
    我的订餐
</div>
<div  id="list">
 
</div>
<div style="width: 100%;height: 100px;"></div>

<script>
    var pageCount = 5;
    var pageIndex = 0;
    $(window).scroll(function () {
        if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
            pageIndex += 1;
            getlist();
        }
    });
    $(function () {
        getlist();
    });

    function getlist() {
        $.post("@Url.Action("GetOrderList","Food")", { pageIndex: pageIndex * pageCount, pageCount: pageCount, status: "@ViewData["status"]" }, function (data) {
            var obj = jQuery.parseJSON(data);
            var str = "";
            for (var i = 0; i < obj.data.length; i++) {

                var item = obj.data[i];
                var paystr = "";
                if (item.Status == "0") {
                    paystr = " <div class='order_fk_op' onclick=\"pay('" + item.OrderNo + "')\">付款</div>"
                        + "<div class='exitorder' onclick=\"delorder('" + item.Id + "')\">取消订餐</div>";
                } else if (item.Status == "1") {
                  //  paystr = "";
                    //paystr = " <div class='order_fk_op' onclick=\"pay('" + item.OrderNo + "')\">尾款支付</div>";
                    paystr = "<div class='exitorder' onclick=\"delorder('" + item.Id + "')\">取消订餐</div>";
                } else {
                    paystr = "";
                }
                str += "<div class='order_list'>"
                    + "<div class='order_info'>"
                    + "<label style='float: left;'>订餐号：" + item.OrderNo + "</label><label style='float: right;'>下单时间：" + item.Date.substring(0, 10) + "</label>"
                    + "</div>";
                var cp = item.Cp.split('>');
                for (var j = 0; j < cp.length - 1; j++) {
                    var temp = cp[j].split(';');
                    str += " <div class='order_g'>"
                        + "<img src='" + temp[0] + "'>"
                        + "<div>"
                        + "<p>" + temp[2] + "</p>"
                        + "<p>数量：" + temp[3] + "份</p>"
                        + " <p style=\"text-align: right;color: red;\">小计：" + parseFloat(temp[1]) + "元</p>"
                        + "</div>"
                        + "</div>";
                }
                str += " <div class=\"ordert_j\">"
                    + " <p style=\"text-align: right;\">"
                    + " 共 3 件商品 合计：￥" + item.Price + "元" +
                    " </p>" +
                    "<p style=\"text-align: right;\">" +
                    "<label>预约时间：" + item.YdDate.replace("T", " ") + "</label>&nbsp;&nbsp;" +
                    " <label style=\"color:red;\">预支付金额：" + parseFloat(item.YPrice) + "元</label>" +
                    "</p>" +
                    "</div>"
                    + "<div class='order_fk'>" +
                paystr
                    + "</div>"
                    + "</div>";
            }
            $("#list").append(str);
        });
    }

    function delorder(orderno) {
        if (confirm("你确定要取消该订单吗？")) {
            $.post("@Url.Action("DelOrder")", { orderid: orderno }, function (row) {
                if (row > 0) {
                    location.reload();
                }
            });
        }
    }
    function pay(orderno) {
        location.href = "/mall/order/startpay?orderno=" + orderno;
    }
</script>